﻿/***
    该文件的作用是，每隔一分钟读取服务器端WebService，
    如果有消息，前台的Title则予以闪烁，切在消息旁边出现一个小的信封标志
*/    
var g_blinkid = 0;
var g_blinkswitch = 0;
var g_blinktitle = document.title;
var g_onlineuser = "";
var g_sysmsg_sound = null;
var g_newmsg_sound = null;
var g_app_num = 0;
var g_appnum = 0;
var g_bappmore = false;

function blinkNewMsg() {
    html1 = "<img src='/Images/ddtx_y.gif' border=0 />";
    html2 = "<img src='/Images/ddtx_g.gif' border=0 />";

    document.getElementById("head_msgdiv").innerHTML = g_blinkswitch % 2 ? html2 : html1;

    document.title = g_blinkswitch % 2 ? "【　　　】 - " + g_blinktitle : "【新消息】 - " + g_blinktitle;

    g_blinkswitch++;
}



function checkNewMsg() {
    //var myAjax = new Ajax.Request(url, { method: "post", parameters: pars, onComplete: function(req) { checkNewMsgShow(req); } });
    CheckNewMessageService.CheckNewMsg(checkNewMsgShow);
}

function stopBlinkNewMsg() {
    if (g_blinkid) {
        clearInterval(g_blinkid);
        g_blinkid = 0;
        document.getElementById("head_msgdiv").innerHTML = "";
        document.title = g_blinktitle;
    }
}

function checkNewMsgShow(result) {
    var r = result;
    stopBlinkNewMsg();
    setTimeout(checkNewMsg, 60000);
    if (r>1) {
        g_blinkid = setInterval(blinkNewMsg, 1000);
    }
    
}

